package com.atguigu.jxc.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.jxc.dao.OverflowListDao;
import com.atguigu.jxc.dao.OverflowListGoodsDao;
import com.atguigu.jxc.entity.DamageListGoods;
import com.atguigu.jxc.entity.OverflowList;
import com.atguigu.jxc.entity.OverflowListGoods;
import com.atguigu.jxc.service.OverflowListGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OverflowListGoodsServiceImpl implements OverflowListGoodsService {
    @Autowired
    private OverflowListGoodsDao overflowListGoodsDao;
    @Autowired
    private OverflowListDao overflowListDao;



    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean save(OverflowList overflowList, String overflowListGoodsStr) {

        Integer integer1 = overflowListDao.saveDamageList(overflowList);



        List<OverflowListGoods> overflowListGoodsList = JSONObject.parseArray(overflowListGoodsStr, OverflowListGoods.class);
        for (OverflowListGoods overflowListGoods : overflowListGoodsList) {

             overflowListGoodsDao.saveDamageGoodsList(overflowListGoods);
        }

        if (integer1 > 0) {
            return true;
        }
        return false;
    }

    //报溢单查询
    @Override
    public Map<String, Object> list(String sTime, String eTime) {
        Map<String, Object> hashMap = new HashMap<>();
        List<OverflowList> overflowListList=overflowListDao.list(sTime,eTime);
        hashMap.put("rows",overflowListList);
        return hashMap;
    }

    //报溢单商品信息
    @Override
    public Map<String, Object> goodsList(Integer overflowListId) {
        Map<String,Object> map=new HashMap<>();
        List<OverflowListGoods> overflowListGoodsList=overflowListGoodsDao.goodsList(overflowListId);
        map.put("rows",overflowListGoodsList);
        return map;
    }
}
